package com.qf.chinatelcom.apiinterface.controller;

import com.qf.chinatelcom.apiinterface.pojo.MessageBody;
import com.qf.chinatelcom.apiinterface.service.CheckSmsService;
import com.qf.chinatelcom.apiinterface.utils.IpUtils;
import com.qianfeng.smsplatform.common.constants.ResutlDataEnum;
import com.qianfeng.smsplatform.common.dto.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/apis")
public class ApiController {

    private CheckSmsService checkSmsService;

    @Autowired
    public void setCheckSmsService(CheckSmsService checkSmsService) {
        this.checkSmsService = checkSmsService;
    }

    @PostMapping("/sendmessagecontent")
    public R sendMessageContent(@RequestBody MessageBody messageBody, HttpServletRequest request) {
        String realIp = IpUtils.getRealIp(request);//获取到唯一id
        List<String> stringList = checkSmsService.checkSms(messageBody, realIp);
        if (stringList != null && stringList.size() > 0) {
            R r = R.getR(ResutlDataEnum.MOBILENUMERROR);//创建一个对象，目的是为了返回同意结果，后边加一个枚举，目的是为了统一结果
            r.put("data", stringList);
            return r;
        }
        return R.ok();
    }

}
